<template>
  <button class="ripple" @click="handleClick">
    <span class="button-content">{{ content }}</span>
  </button>
</template>

<script>
export default {
  name: 'RippleButton',
  props: {
    content: {
      type: String,
      default: 'Click Me'
    }
  },
  methods: {
    handleClick(e)
    {
      // 获取按钮的位置和尺寸
      const buttonRect = this.$el.getBoundingClientRect()
      const x = e.clientX - buttonRect.left
      const y = e.clientY - buttonRect.top

      // 创建动画圆圈
      const circle = document.createElement('span')
      circle.classList.add('circle')
      circle.style.top = `${y}px`
      circle.style.left = `${x}px`

      // 将动画圆圈添加到按钮上
      this.$el.appendChild(circle)

      // 动画结束后移除圆圈
      setTimeout(() => circle.remove(), 500)
    }
  }
}
</script>

<style scoped>
* {
  box-sizing: border-box;
}

button {
  background-color: purple;
  color: #fff;
  border: 1px purple solid;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 20px 30px;
  overflow: hidden;
  margin: 10px 0;
  position: relative;
  cursor: pointer;
}

button:focus {
  outline: none;
}

button .circle {
  position: absolute;
  background-color: #fff;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  animation: scale 0.5s ease-out;
}

@keyframes scale {
  to {
    transform: translate(-50%, -50%) scale(3);
    opacity: 0;
  }
}
</style>
